﻿using System;

namespace JsValidator
{
    public enum ReportEntryType
    {
        Error,
        Warning
    }
    public static class ReportEntryTypeExtensions
    {
        public static string ToVsString(this ReportEntryType type)
        {
            switch (type)
            {
                case ReportEntryType.Error:
                    return "error";
                case ReportEntryType.Warning:
                    return "warning";
                default:
                    throw new ArgumentOutOfRangeException("type", type, "");
            }
        }
    }

    internal interface IReporter
    {
        void Report(string text, ReportEntryType type);
        void Report(ReportEntryType type, string message, string filename, string lineNumber, int column);
        void ReportWarning(string text);
        void ReportError(string text);
    }

    internal class Reporter : IReporter
    {
        public virtual void Report(string text, ReportEntryType type)
        {
            var prefix = type.ToVsString();

            Console.WriteLine(String.Format("{0} JS0000: {1}", prefix, text));
        }


        public virtual void Report(ReportEntryType type, string message, string filename, string lineNumber, int column)
        {
            Console.WriteLine("{0}({1},{2}): {3} JS0000: {4}",
                                  filename,
                                  lineNumber,
                                  column,
                                  type.ToVsString(),
                                  message
                    );
        }


        public virtual void ReportWarning(string text)
        {
            Report(text, ReportEntryType.Warning);
        }

        public virtual void ReportError(string text)
        {
            Report(text, ReportEntryType.Error);
        }
    }
}